<?php
require('../include/init.php');
require('check_login.php');
$act = $_REQUEST['act'];
if($act == 'add_manage') { 
	$smarty->assign('add_manage', 1);
} elseif ($act == 'add') { 
	$admin_name = $_GET['admin_name'];
	$admin_pass = md5($_GET['admin_pass']);
	$num = $GLOBALS['db']->getOne("select count(*) from kyz_admin where admin_name='$admin_name' limit 1");
	if($num > 0) { 
		echo "haved";exit();
	} else { 
		$GLOBALS['db']->query("insert into kyz_admin(admin_name, admin_pass) values('$admin_name', '$admin_pass')");
		echo "ok";exit();
	}
} elseif ($act == 'edit_manage') { 
	$smarty->assign('admin_id', $_GET['admin_id']);
	$smarty->assign('edit_manage', 1);
} elseif ($act == 'save') {
	$admin_id = $_GET['admin_id'];
	$old_pass = md5($_GET['old_pass']);
	$new_pass = md5($_GET['new_pass']);
	$num = $GLOBALS['db']->getOne("select count(*) from kyz_admin where admin_id='$admin_id' and admin_pass='$old_pass' limit 1");
	 if(!$num) {
	 	echo 'oldpass_error'; exit();
	 }
	$GLOBALS['db']->query("update kyz_admin set admin_pass='$new_pass' where admin_id='$admin_id'");	
	echo 'ok'; exit();
} elseif ($act == 'del'){
	$admin_id = $_GET['admin_id'];
	$GLOBALS['db']->query("delete from kyz_admin where admin_id=$admin_id");
	echo 1; exit();
} else { 
	$admin_list = $GLOBALS['db']->getAll("select * from kyz_admin");
	$smarty->assign('admin_list', $admin_list);
}


$smarty->display('admin/manage.html');

?>